import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/entrys/rp/inv_list_details_entity.dart';
import 'package:xiongan_app_yy/entrys/rp/warehousing_returns_details_entity.dart';
import 'package:xiongan_app_yy/net/internet_api.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';
import 'package:xiongan_app_yy/widgets/comm/text_card_widget.dart';
import 'package:xiongan_app_yy/widgets/comm/text_exhibition_card_widget.dart';

//信息-入库退货
class WarehousingReturnsDetails extends StatefulWidget {
  final String args;

  @override
  State<StatefulWidget> createState() {
    return WarehousingReturnsDetailsState();
  }
  WarehousingReturnsDetails(this.args);
}

class WarehousingReturnsDetailsState extends State<WarehousingReturnsDetails> {
  String path;
  var _futureBuilderFuture;
  String data;
  WarehousingReturnsDetailsEntity entity;
  @override
  void initState() {
    super.initState();
    _futureBuilderFuture = getData();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
        backgroundColor: Color(0XFF00A5F1),
        title: Text(
          "详情",
          style: TextStyle(fontSize: 18),
        ),
        elevation: 0,
        centerTitle: true,
      ),
      body: FutureBuilder(
        builder: _buildFuture,
        future: _futureBuilderFuture,
      ),
    );
  }

  ///snapshot就是_calculation在时间轴上执行过程的状态快照
  Widget _buildFuture(BuildContext context, AsyncSnapshot snapshot) {
    switch (snapshot.connectionState) {
      case ConnectionState.none:
        print('还没有开始网络请求');
        return Text('还没有开始网络请求');
      case ConnectionState.active:
        print('active');
        return Text('ConnectionState.active');
      case ConnectionState.waiting:
        print('waiting');
        return Center(
          child: CircularProgressIndicator(),
        );
      case ConnectionState.done:
        print('done');
        if (snapshot.hasError) {
          return Text('Error: ${snapshot.error}');
        }
        return _createListView(context, snapshot);
      default:
        return null;
    }
  }
  Widget _createListView(BuildContext context, AsyncSnapshot snapshot) {
    data = snapshot.data.toString();
    Map<String, dynamic> dataMap = jsonDecode(data);
    if (dataMap["flag"] == "success") {
      entity = WarehousingReturnsDetailsEntity.fromJson(dataMap["datas"]);
    }
    return Scrollbar(
        child: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Column(
          children: <Widget>[
            TextExhibitionCardWidget(
                distance:
                EdgeInsets.only(right: 15, left: 15, bottom: 16, top: 16),
                title: "原因",
                exhibitionText: entity.remark??""),
            TextExhibitionCardWidget(
                distance:
                EdgeInsets.only(right: 15, left: 15, bottom: 16, top: 16),
                title: "入库退货单号",
                exhibitionText: entity.taskno),
            TextExhibitionCardWidget(
                distance:
                EdgeInsets.only(right: 15, left: 15, bottom: 16, top: 16),
                title: "原入库单号",
                exhibitionText: entity.warehouseinno),
            TextExhibitionCardWidget(
                distance:
                EdgeInsets.only(right: 15, left: 15, bottom: 16, top: 16),
                title: "供应商",
                exhibitionText: entity.supplyname??""),
            TextExhibitionCardWidget(
                distance:
                EdgeInsets.only(right: 15, left: 15, bottom: 16, top: 16),
                title: "工程名称",
                exhibitionText: entity.projectname),
            TextExhibitionCardWidget(
                distance:
                EdgeInsets.only(right: 15, left: 15, bottom: 16, top: 16),
                title: "物资件数",
                exhibitionText: entity.total.toString()),
            TextCardWidget(
                onPressed: () {
                  //Navigator.pushNamed(context, "/storageDetails",arguments: detailsBean);
                  Navigator.pushNamed(context, "/warehousing_mterial_details",arguments:entity.taskDetailList);
                },
                title: "物资明细",
                border: Border(
                    bottom: BorderSide(width: 1, color: Color(0xffdddddd)),
                    top: BorderSide(width: 1, color: Color(0xffdddddd))))
          ],
        )));


  }
  Future getData() async {
    var response = InternetAPI.getInstance().dio.get(
    "OMS/MiBackProductTask/GetMiBackProductTask",queryParameters: {
      'operaterUserId': DataSingleton().Data.id,
      'userId': DataSingleton().Data.id,
      'tenantId': DataSingleton().Data.tenantId,
      'id': widget.args}
    );
    return response;
  }
}
